package co.chonghao.ch_kuaichong_user.ui.views;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import co.chonghao.ch_kuaichong_user.R;


/**
 * Created by Administrator on 2017/4/12 0012.
 *
 */

public class MyToast {
    public static final int LENGTH_SHORT = Toast.LENGTH_SHORT;
    public static final int LENGTH_LONG = Toast.LENGTH_LONG;

    private Toast toast;
    private Context mContext;
    private TextView toastTextField;
    private ImageView warning;

    public MyToast(Context context) {
        mContext = context;
        toast = new Toast(mContext);
        toast.setGravity(Gravity.CENTER, 0, 0);
        View toastRoot = LayoutInflater.from(context).inflate(R.layout.layout_toast_bg, null);
        toastTextField = (TextView) toastRoot.findViewById(R.id.toast_text);
        warning = (ImageView) toastRoot.findViewById(R.id.ivWarning);
        toast.setView(toastRoot);
    }

    public void setWarningVisibility(boolean visibility){
        if (visibility){
            warning.setVisibility(View.VISIBLE);
        }else {
            warning.setVisibility(View.GONE);
        }
    }

    public void setDuration(int d) {
        toast.setDuration(d);
    }

    public void setText(String t) {
        toastTextField.setText(t);
    }

    public static MyToast makeText(Context context, String text, int duration) {
        MyToast toastCustom = new MyToast(context);
        toastCustom.setText(text);
        toastCustom.setDuration(duration);
        return toastCustom;
    }

    public void show() {
        toast.show();
    }
}
